/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ecommerce.test;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author Yoonan
 */
@Controller
@RequestMapping("/test")
public class Method {

    /**
     * example http://localhost:8084/Pattern/test/method1
     * http://localhost:8084/Pattern/test/method1/second
     *
     * @return
     */
    @RequestMapping(value = {"/method1", "/method1/second"})
    @ResponseBody
    public String method1() {
        return "method1";
    }

    /**
     * example http://localhost:8084/Pattern/test/method2
     *
     * @return
     */
    @RequestMapping(value = "/method2", method = RequestMethod.POST)
    @ResponseBody
    public String method2() {
        return "method2";
    }

    /**
     * example http://localhost:8084/Pattern/test/method3
     *
     * @return
     */
    @RequestMapping(value = "/method3", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public String method3() {
        return "method3";
    }

    /**
     * example http://localhost:8084/Pattern/test/method4 with name=wasin
     *
     * @return
     */
    @RequestMapping(value = "/method4", headers = "name=wasin")
    @ResponseBody
    public String method4() {
        return "method4";
    }

    /**
     * example http://localhost:8084/Pattern/test/method5 with name=wasin,id=1
     *
     * @return
     */
    @RequestMapping(value = "/method5", headers = {"name=wasin", "id=1"})
    @ResponseBody
    public String method5() {
        return "method5";
    }

    /**
     * http://localhost:8084/Pattern/test/method6
     * @return 
     */
    @RequestMapping(value = "/method6", produces = {"application/json", "application/xml"}, consumes = "text/html")
    @ResponseBody
    public String method6() {
        return "method6";
    }

    /**
     * example http://localhost:8084/Pattern/test/method7/10
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/method7/{id}")
    @ResponseBody
    public String method7(@PathVariable("id") int id) {
        return "method7 with id=" + id;
    }

    /**
     * example http://localhost:8084/Pattern/test/method8/10/wasin
     *
     * @param id
     * @param name
     * @return
     */
    @RequestMapping(value = "/method8/{id:[\\d]+}/{name}")
    @ResponseBody
    public String method8(@PathVariable("id") long id, @PathVariable("name") String name) {
        return "method8 with id= " + id + " and name=" + name;
    }
}
